package com.pigcloud.sop.gatewaycommon.gateway.route;

import com.pigcloud.sop.gatewaycommon.bean.RouteDefinition;
import com.pigcloud.sop.gatewaycommon.bean.ServiceDefinition;
import com.pigcloud.sop.gatewaycommon.bean.TargetRoute;
import org.springframework.util.StringUtils;

/**
 *  描述信息:
 * @Author wangfm
 * @Date: 2024/1/2
 */
public class GatewayTargetRoute implements TargetRoute {

    private final ServiceDefinition serviceDefinition;
    private final RouteDefinition routeDefinition;


    public GatewayTargetRoute(ServiceDefinition serviceDefinition, RouteDefinition routeDefinition) {
        this.serviceDefinition = serviceDefinition;
        this.routeDefinition = routeDefinition;
    }

    @Override
    public String getFullPath() {
        String serviceId = serviceDefinition.getServiceId();
        String path = StringUtils.trimLeadingCharacter(routeDefinition.getPath(), '/');
        return "/" + serviceId + "/" + path;
    }

    @Override
    public ServiceDefinition getServiceDefinition() {
        return serviceDefinition;
    }

    @Override
    public RouteDefinition getRouteDefinition() {
        return routeDefinition;
    }
}
